package com.g17.virtualpetbackend.repo;

import com.g17.virtualpetbackend.entity.Record;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;

import java.util.List;
import java.util.Optional;

public interface RecordRepository extends Neo4jRepository<Record,Long> {

    @Query("MATCH (n:record) WHERE n.pet_name=$petName RETURN n")
    Record findByPetName(String petName);

    @Query("MATCH (n:record) WHERE id(n) = $id RETURN n")
    Optional<Record> findById(Long id);

    @Query("MATCH (n:record) WHERE n.pet_name CONTAINS $keyword OR n.master_name CONTAINS $keyword OR n.disease_name CONTAINS $keyword OR n.species CONTAINS $keyword OR n.symptom CONTAINS $keyword OR n.diagnose CONTAINS $keyword OR n.treatment CONTAINS $keyword OR n.medicine CONTAINS $keyword OR n.followup CONTAINS $keyword OR n.doctor CONTAINS $keyword RETURN n")
    List<Record> findByKeyword(String keyword);

    @Query("MATCH (n:record)   RETURN n")
    List<Record> findAllRecords();

    @Query("CREATE (n:record {pet_name:$petName, master_name:$masterName, disease_name:$diseaseName, species:$species, symptom:$symptom, symptom_picture:$symptomPicture, symptom_video:$symptomVideo, diagnose:$diagnose, treatment:$treatment, medicine:$medicine, followup:$followup, followup_picture:$followupPicture, followup_video:$followupVideo, doctor:$doctor} ) RETURN n")
    Record createRecord(String petName, String masterName, String diseaseName, String species, String symptom, List<String>  symptomPicture, String symptomVideo, String diagnose, String treatment, String medicine, String followup, List<String> followupPicture, String followupVideo, String doctor);

    @Query("MATCH (n:record) WHERE id(n) = $id SET n = {pet_name:$petName, master_name:$masterName, disease_name:$diseaseName, species:$species, symptom:$symptom, symptom_picture:$symptomPicture, symptom_video:$symptomVideo, diagnose:$diagnose, treatment:$treatment, medicine:$medicine, followup:$followup, followup_picture:$followupPicture, followup_video:$followupVideo, doctor:$doctor} RETURN n")
    Record updateRecord(Long id, String petName, String masterName, String diseaseName, String species, String symptom, List<String> symptomPicture, String symptomVideo, String diagnose, String treatment, String medicine, String followup, List<String> followupPicture, String followupVideo, String doctor);

    @Query("MATCH (n:record) WHERE id(n) = $id DELETE n RETURN n")
    Record deleteRecordById(Long id);

    @Query("MATCH (n:record) WHERE id(n) = $id  RETURN n")
    Record findSingleRecord(Long id);
}
